/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package servlets;

import codigoJava.GestorBD;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.annotation.Resource;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.sql.DataSource;
/**
 *
 * @author CACEDA
 */
@WebServlet(name = "BaseServlet", urlPatterns = {"/BaseServlet"})
public class BaseServlet extends HttpServlet 
{

    @Resource(name = "conPalomitasPool")
    public DataSource jdbcconPalomitas;
    public GestorBD adb;

    @Override
    public void init() throws ServletException {
        super.init();
        adb = new GestorBD(jdbcconPalomitas);
    }


    public void redirect(String url, HttpServletRequest request, HttpServletResponse response)
        throws IOException{
        response.sendRedirect(response.encodeRedirectURL(request.getContextPath()+url));
    }

    public String safeURL(String url, HttpServletRequest request, HttpServletResponse response)
        throws IOException{
        return response.encodeURL(request.getContextPath()+url);
    }

    public void dispatch (String url, HttpServletRequest request, HttpServletResponse response)
    {
        try {
            RequestDispatcher rd = getServletContext().getRequestDispatcher(url);
            rd.forward(request, response);
        } catch (ServletException ex) {
            Logger.getLogger(BaseServlet.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(BaseServlet.class.getName()).log(Level.SEVERE, null, ex);
        }

    }
    /** Returns a short description of the servlet.*/
    @Override
    public String getServletInfo() {
        return "Short description";
    }
}
